//
//  ViewController.m
//  NSCodingDemo
//
//  Created by wanglei on 17/3/7.
//  Copyright © 2017年 wanglei. All rights reserved.
//

#import "ViewController.h"
#import "Man.h"
#import "Person.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    Person *obj = [[Person alloc] init];
    obj.name = @"Jack";
    obj.age = 27;
    
    obj.friend = [[Man alloc] init];
    obj.friend.name = @"Tom";
    
    //归档
    [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:obj] forKey:@"myObj"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    //反归档
    Person *p = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:@"myObj"]];
    
    NSLog(@"p.name:%@, p.age:%lu, p.friend.name = %@", p.name, p.age, p.friend.name);

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
